﻿using System;
using DDU.Infrastructure;
using System.Data.Linq.Mapping;
using System.Reflection;

namespace DDU.DataModel
{
    [Table(Name = "T_Schedules")]
    public class ScheduleInfo : NotificationObject
    {
        private string _guid = System.Guid.NewGuid().ToString();
        private string _semesterGuid;
        private DayOfWeek _dayOfWeek = DateTime.Today.DayOfWeek;
        private string _name;
        private string _teacher;
        private string _roomOrPlace;
        private DateTime _startTime = DateTime.Now;
        private DateTime _endTime = DateTime.Now;
        private bool _routineCourse = true;

        [Column(IsPrimaryKey=true)]
        public string Guid
        {
            get { return _guid; }
            set
            {
                _guid = value;
                RaisePropertyChanged(() => Guid);
            }
        }

        [Column]
        public string SemesterGuid
        {
            get { return _semesterGuid; }
            set
            {
                _semesterGuid = value;
                RaisePropertyChanged(() => SemesterGuid);
            }
        }

        [Column]
        public DayOfWeek DayOfWeek
        {
            get { return _dayOfWeek; }
            set
            {
                _dayOfWeek = value;
                RaisePropertyChanged(() => DayOfWeek);
            }
        }

        [Column]
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                RaisePropertyChanged(() => Name);
            }
        }

        [Column]
        public string Teacher
        {
            get { return _teacher; }
            set
            {
                _teacher = value;
                RaisePropertyChanged(() => Teacher);
            }
        }

        [Column]
        public string RoomOrPlace
        {
            get { return _roomOrPlace; }
            set
            {
                _roomOrPlace = value;
                RaisePropertyChanged(() => RoomOrPlace);
            }
        }

        [Column]
        public DateTime StartTime
        {
            get { return _startTime; }
            set
            {
                _startTime = value;
                RaisePropertyChanged(() => StartTime);
            }
        }

        [Column]
        public DateTime EndTime
        {
            get { return _endTime; }
            set
            {
                _endTime = value;
                RaisePropertyChanged(() => EndTime);
            }
        }

        [Column]
        public bool RoutineCourse
        {
            get { return _routineCourse; }
            set
            {
                _routineCourse = value;
                RaisePropertyChanged(() => RoutineCourse);
            }
        }

        public event EventHandler<PropertyArgs> ValueChanged = delegate { };

        protected override void RaisePropertyChanged(string propertyName)
        {
            base.RaisePropertyChanged(propertyName);
            ValueChanged.Invoke(this, new PropertyArgs()
            {
                Property = GetType().GetProperty(propertyName)
            });
        }
    }
}
